﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data.Entity.Core.Metadata.Edm;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Common.Helper
{
    public class ReflectHelper
    {
        public static Dictionary<string, string> GetSqlEntityDesction(Type type)
        {
            var properties = type.GetProperties();
            Dictionary<string, string> result = new Dictionary<string, string>();
            foreach (var prop in properties)
            {
                var sugarColumnAttribute = prop.GetCustomAttributes(typeof(SugarColumn), false).FirstOrDefault() as SugarColumn;

                if (sugarColumnAttribute != null && !string.IsNullOrEmpty(sugarColumnAttribute.ColumnDescription))
                {
                    result.Add(prop.Name, sugarColumnAttribute.ColumnDescription);
                }
            }
            return result;
        }

        public static Dictionary<string, Type> GetSqlEntityDesctionAndType(Type type)
        {
            var properties = type.GetProperties();
            Dictionary<string, Type> result = new Dictionary<string, Type>();
            foreach (var prop in properties)
            {
                var sugarColumnAttribute = prop.GetCustomAttributes(typeof(SugarColumn), false).FirstOrDefault() as SugarColumn;

                if (sugarColumnAttribute != null && !string.IsNullOrEmpty(sugarColumnAttribute.ColumnDescription))
                {
                    result.Add(prop.Name, prop.GetType());
                }
            }
            return result;
        }
    }
}
